package com.my.supplier.service.impl;

import com.my.supplier.entity.Supplier;
import com.my.supplier.mapper.SupplierMapper;
import com.my.supplier.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service
public class SupplierServiceImpl implements SupplierService {
    @Autowired
    private SupplierMapper supplierMapper;


    @Override
    public List<Supplier> getSupplier(Map<String, Object> map) {
        return supplierMapper.selectByExample(map);
    }

    @Override
    public void addSupplier(Supplier supplier) {
    	
    	int i=supplierMapper.count();
    	int j=i+1;
    	String coding=null;
    	if(j<10) {
    		coding="V000"+j;
    	}
    	if(j>=10) {
    		coding="V00"+j;
    	}
    	
    	supplier.setSupCoding(coding);
    	
    	supplier.setSupValid(Short.valueOf("1"));
        supplierMapper.insert(supplier);
    }

	@Override
	public void updateSupplicer(Supplier supplier) {
		supplierMapper.updateByPrimaryKey(supplier);
	}

	@Override
	public Supplier getSupplierById(Long valueOf) {
		return supplierMapper.selectByPrimaryKey(valueOf);
	}
}
